//
//  ByShopTopPartVC.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/1.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByShopSecondPartVC.h"

// vc
#import "ByShopSearchVC.h"

// view
#import "ByViewShopSecondPartTable.h"

@interface ByShopSecondPartVC ()

@property (nonatomic, strong) ZKSegmentControl *segment;

@end

@implementation ByShopSecondPartVC

#pragma mark - view method
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"商城";
    
    [self addLeftBackBarButtonItem];
    [self addBYItemviews:@[@"搜索"] mode:ByNavigationItemModeImage position:ByNavigationItemPositionModeRight];
    
    [self createViews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self getData];
    });
}


#pragma mark - 获取数据
- (void)getData {
    
    [ByCoreToolAlert showLoadind:@"正在加载..."];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        _segment.segmentsArray = @[@"全部", @"衣服", @"裤子", @"衬衣", @"牛仔裤", @"衬衫", @"T恤", @"短裤"];
        _segment.dynamicalAddContentViewBlock = ^ (void (^contentViewFetchBlock)(ZKSegmentContentView *contentView), NSInteger index) {
            
            ByViewShopSecondPartTable *contentView = [[ByViewShopSecondPartTable alloc] init];
            contentView.index = index;
            if (contentViewFetchBlock) {
                contentViewFetchBlock(contentView);
            }
        };
        [ByCoreToolAlert hideHud];
    });
}

#pragma mark - 创建视图
- (void)createViews {
    
    _segment = [[ZKSegmentControl alloc] init];
    _segment.segmentSelectTint = BY_GOLD_COLOR;
    _segment.segmentTitleWidthDynamically = @YES;
    _segment.segmentMaxTitles = @5;
    _segment.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_segment];
    [_segment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        if (@available(ios 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(self);
        }
    }];
}

#pragma mark - 点击
- (void)rightItemsAction:(NSInteger)rightIndex {
    
    [self by_normalPush:[ByShopSearchVC new] hasNavi:true];
}

@end
